package com.yichen.music;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yichen.util.Actor_MusicUtils;
import com.yichen.util.ActorsUtils;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class Actor_Music_List extends ListActivity implements
		OnItemClickListener {
	List<String> music_name_data;
	List<Map<String, String>> data_base;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		String actor_id = intent.getStringExtra("actor_ID");
		Actor_MusicUtils mm = new Actor_MusicUtils();
		data_base = mm.getMusicByActorID(actor_id);

		music_name_data = new ArrayList<String>();

		for (Map<String, String> map : data_base) {
			String music_name = map.get("music_name");
			music_name_data
					.add(music_name.substring(0, music_name.indexOf("(")));
			// System.out.println(map.get("music_NAME").split("(")[0]);

		}

		ArrayAdapter<String> data_adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, music_name_data);

		this.setListAdapter(data_adapter);
		this.getListView().setOnItemClickListener(this);

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
//		System.out.println("++++++++++:::::"
//				+ data_base.get(arg2).get("music_id"));// 获取歌曲的ID

		Intent intent = new Intent();
		intent.setClass(this, MusicPlay.class);
		intent.putExtra("song_id", data_base.get(arg2).get("music_id"));
		intent.putExtra("song_name", music_name_data.get(arg2));
		intent.putExtra("actor_name", data_base.get(arg2).get("actor_name"));

		startActivity(intent);

	}
}
